package scriptrunner.parser;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.TreeMap;

import scriptrunner.execution.*;
import scriptrunner.execution.parameter.*;

public class Testtest {

	/**
	 * @param args
	 */
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {
			// parser p = new parser( new Lexer( new
			// FileInputStream("J:\\testScript\\1.txt") ) );
			// parser p = new parser( new Lexer( new
			// FileInputStream("J:\\testScript\\2.txt") ) );
			// parser p = new parser( new Lexer( new
			// FileInputStream("J:\\testScript\\3.txt") ) );
			// parser p = new parser( new Lexer( new
			// FileInputStream("J:\\testScript\\4.txt") ) );
			// parser p = new parser( new Lexer( new
			// FileInputStream("J:\\testScript\\5.txt") ) );
			
			String[] preFunc = {"scriptrunner.execution.WriteLogFunction",
					"scriptrunner.execution.ServerTimeFunction",
					"scriptrunner.execution.ListAddElementFunction"};
			
			FunctionRegister.GetInstance().RegisterPredefinedFunction(preFunc);

			System.out.println("Start...");

			parser p = new parser(new Lexer(new FileInputStream(
					"test_files\\testScript\\9.txt")));
			p.parse();
			
			TreeMap<String,String> httpMap = new TreeMap<String,String>();
			httpMap.put("name", "zzt");
			httpMap.put("sex", "male");
			httpMap.put("a", "10");
			httpMap.put("b", "3f");

			scriptrunner.execution.Session se = new scriptrunner.execution.Session(
					new HttpParameter(httpMap));
			scriptrunner.execution.ValueObject v = FunctionRegister
					.GetInstance().GetMainFunction().Execute(se);
			
			System.out.println(v.toString());

			// scriptrunner.execution.ValueObject v = se.getReturnResult();

			// if (v instanceof scriptrunner.execution.ValueIntegerObject ) {
			// ValueIntegerObject intValue = (ValueIntegerObject)v;
			// System.out.println( intValue.GetValue() );
			// } else if ( v instanceof scriptrunner.execution.ValueFloatObject
			// ) {
			// ValueFloatObject floatValue = (ValueFloatObject)v;
			// System.out.println( floatValue.GetValue() );
			// } else if ( v instanceof scriptrunner.execution.ValueStringObject
			// ) {
			// ValueStringObject stringValue = (ValueStringObject)v;
			// System.out.println( stringValue.GetValue() );
			// }
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecuteErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
